package com.wdd.myplatform.controller.mqtt;

import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author wdd 2022/4/25
 */
@Component
public class MqttCallBackContext {
    private final Map<String, AbstractMqttCallBackStrategy> callBackMap = new ConcurrentHashMap<>();

    /**
     * 默认构造函数
     *
     * @param callBackMap 回调集合
     */
    public MqttCallBackContext(Map<String, AbstractMqttCallBackStrategy> callBackMap) {
        this.callBackMap.clear();
        callBackMap.forEach((k, v) -> this.callBackMap.put(k, v));
    }

    /**
     * 获取MQTT回调类
     *
     * @param clientId 客户端ID
     * @return MQTT回调类
     */
    public AbstractMqttCallBackStrategy getCallBack(String clientId) {
        return this.callBackMap.get(clientId);
    }
}
